package com.test.group6.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.test.group6.domain.WorkesIds;
import com.test.group6.service.DeleteWorkesService;

/**
 * Title WorkersController.java
 * Description 企业高管信息维护controller层
 * @author leng_qqing
 * @date 2021年7月23日
 * @version 1.0
 */
@RestController
public class DeleteWorkersController {
	@Autowired
	DeleteWorkesService deleteWorkesService;
	/**
	 * @Description 单条删除企业高管信息
	 * @param workerId 企业高管编号
	 * @return 操作执行结果，成功返回success，失败返回error
	 */
	@RequestMapping("/deleteWorkesById")
	public String deleteWorkesById(String workesId ) {
		//根据企业高管编号删除企业高管信息
		int workesCount = deleteWorkesService.deleteWorkesById(workesId);
		if(workesCount >0) {
			return "success";
		}else {
			return "error";
		}
	}
	/**
	 * @Description 批量删除企业高管信息
	 * @param workerId 企业高管编号数组
	 * @return 操作执行结果，成功返回success，失败返回error
	 */
	@RequestMapping("/deleteBatchWorkers")
	public String deleteBatchWorkes(WorkesIds workesId) {
		System.out.println(workesId.getWorkesId()[0].length());
		System.out.println(workesId.getWorkesId()[1]);
		
		
		int i = 0;
		//循环遍历企业高管编号数组
		while(i < workesId.getWorkesId().length) {
			//根据企业高管编号删除企业高管信息
			int workesCount = deleteWorkesService.deleteWorkesById(workesId.getWorkesId()[i]);
			if(workesCount >0) {
				i ++;	
			}else {
				return "error";
			}
		}
		return "success";
	}
	

}
